//https://leetcode.cn/problems/convert-bst-to-greater-tree/
package codeRandomThoughts.Test538把二叉搜索树转换为累加树;

import codeRandomThoughts.utils.TreeNode;

public class Solution {
    TreeNode tem;
    public TreeNode convertBST(TreeNode root) {
        convert(root);
        return root;
    }
    void convert(TreeNode node){
        if (node == null) return;
        convert(node.right);
        if (tem!=null) {
            node.val+= tem.val;
        }
        tem = node;
        convert(node.left);
    }
}
